/**
 * Project: topdt-jbpm
 * Copyright 2013  Top Digital Technology  Co. Ltd.
 * All right reserved.
 */
package com.topdt.jbpm.extension;

import java.sql.Timestamp;

import org.jbpm.api.listener.EventListener;
import org.jbpm.api.listener.EventListenerExecution;

import com.thx.common.util.ThreadLocalContext;
import com.topdt.jbpm.model.Work;
import com.topdt.jbpm.service.Context;
import com.topdt.jbpm.service.JbpmService;

/**
 * 建立日期 : 2013-5-5 下午4:51:26<br>
 * 作者 : balance<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
public class ProcessListener implements EventListener {

	private static final long serialVersionUID = -2702310880152895356L;

	public void notify(EventListenerExecution execution) throws Exception {
		Context contex = (Context) execution.getVariable(Context.KEY);
		String workId = contex.getWorkId();
		JbpmService jbpmService = JbpmService.getJbpmService();
		Work work = jbpmService.getWorkDao().get(workId);
		work.setWorkState(Work.STATE_END);
		work.setEndTime(new Timestamp(System.currentTimeMillis()));
		work.setCurActivityName("[结束]");
		jbpmService.getWorkDao().update(work);
		ThreadLocalContext.set("next_circs", Work.STATE_END);
	}

}
